﻿Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms

Public Class fPrecoCustoOrcamento

    Private Sub fPrecoCustoOrcamento_Load(sender As Object, e As EventArgs) Handles MyBase.Load

       
        Dim db As New lqOrcamentoDataContext

        Dim ListaAno = (From c In db.tblPrecoCustoOrcamentos Group By c.Ano Into Group _
                      Select Ano)

        For Each anoins In ListaAno
            ComboBoxEdit1.Properties.Items.Add(anoins.ToString)
        Next
        ComboBoxEdit1.SelectedIndex = ListaAno.Count

        ItemUnTableAdapter.Fill(DsManutencaoPrecoCusto.ItemUn, GlobalVariables.Un, ComboBoxEdit1.EditValue, GlobalVariables.Empresa)

        GridView1.BestFitColumns()
    End Sub

    Private Sub GridView1_CellValueChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs) Handles GridView1.CellValueChanged
        Dim CTEsperado As Decimal = 0
        If e.Column.Name = colPCtSugerido.Name.ToString Then
            CTEsperado = e.Value
            ItemUnTableAdapter.UpdateQueryPCtSugerido(CTEsperado, ComboBoxEdit1.EditValue, GridView1.GetFocusedRowCellValue(colNo_), GlobalVariables.Empresa)
        End If
    End Sub

    Private Sub RepositoryItemButtonEdit1_ButtonClick(sender As Object, e As DevExpress.XtraEditors.Controls.ButtonPressedEventArgs) Handles RepositoryItemButtonEdit1.ButtonClick
        GridView1.SetFocusedRowCellValue(colPCtSugerido, 0)

    End Sub

    Private Sub ComboBoxEdit1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBoxEdit1.SelectedIndexChanged
        ItemUnTableAdapter.Fill(DsManutencaoPrecoCusto.ItemUn, GlobalVariables.Un, ComboBoxEdit1.EditValue, GlobalVariables.Empresa)
    End Sub
End Class